﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Services.System.Article;
using Simple.Services.System.Article.Model;
using Simple.Services.System.ClassRoom;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 轮播图管理
/// </summary>
[Route("api/Slideshow/[action]")]
[ApiController]
[Authorize]
public class SlideshowController : ControllerBase
{
    private readonly SlideshowService _slideshowService;

    public SlideshowController(SlideshowService slideshowService)
    {
        _slideshowService = slideshowService;
    }

    /// <summary>
    /// 查询轮播图内容详情
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> GetInfo([FromQuery] Guid? Id)
    {
        var data = await _slideshowService.GetAsync(Id);
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 轮播图列表分页查询
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> Page([FromQuery] SlideshowQueryPageInputModel model)
    {
        var data = await _slideshowService.GetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 添加轮播图
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Add([FromForm] SlideshowCreateOrUpdateModel model)
    {
        await _slideshowService.AddAsync(model);
        return AppResult.Status200OK("新增成功");
    }

    /// <summary>
    /// 编辑轮播图
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Edit([FromForm] SlideshowCreateOrUpdateModel model)
    {
        await _slideshowService.UpdateAsync(model);
        return AppResult.Status200OK("更新成功");
    }

    /// <summary>
    /// 删除轮播图
    /// </summary>
    /// <param name="IdList"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Delete([FromBody] List<Guid?> IdList)
    {
        await _slideshowService.DeleteAsync(IdList);
        return AppResult.Status200OK("删除成功");
    }

    /// <summary>
    /// 获取系统内部资源数据(机构数据隔离)
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> GetAllInternalResources()
    {
        var data = await _slideshowService.GetAllInternalResources();
        return AppResult.Status200OK(data: data);
    }
}
